<template>
  <div class="pages">
    <!-- 查询表单 -->
    <el-form :inline="true">
      <el-form-item label="提现状态">
        <el-select v-model="type">
          <el-option
            v-for="item in typeList"
            :key="item"
            :label="item"
            :value="item"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="商家店铺ID">
        <el-input type="text" v-model="stid" placeholder="请输入商家店铺ID" />
      </el-form-item>
      <el-form-item label="申请时间">
        <DatePicker v-model="cTime" :timevalue1="cTime"></DatePicker>
      </el-form-item>
      <el-form-item label="打款时间">
        <DatePicker v-model="cTime1" :timevalue1="cTime1"></DatePicker>
      </el-form-item>
      <!-- <el-form-item label="">
        <DatePicker v-model="cTime" :timevalue1="cTime"></DatePicker>
      </el-form-item> -->
      <el-form-item>
        <el-button type="primary" @click="getData">查询</el-button>
      </el-form-item>
    </el-form>
    <el-col :span="1.5">
      <el-button
        type="warning"
        plain
        icon="el-icon-download"
        size="mini"
        @click="handleExport"
        v-hasPermi="['ds:productOrder:export']"
        >导出</el-button
      >
    </el-col>

    <el-table :data="list" border>
      <el-table-column type="index" label="序号"></el-table-column>
      <el-table-column prop="id" label="ID" width="90"></el-table-column>
      <el-table-column prop="stid" label="商家ID" width="90"></el-table-column>
      <el-table-column prop="type" label="类型" width="90"></el-table-column>
      <el-table-column
        prop="inOut"
        label="支出/收入"
        width="90"
      ></el-table-column>
      <el-table-column prop="name" label="名称"></el-table-column>
      <el-table-column prop="amount" label="金额"></el-table-column>
      <el-table-column prop="balance" label="用户余额"></el-table-column>
      <el-table-column
        prop="detailed"
        label="详情"
        width="150"
      ></el-table-column>
      <el-table-column
        prop="updateBy"
        label="银行卡号"
        width="150"
      ></el-table-column>
      <el-table-column
        prop="createBy"
        label="真实姓名"
        width="150"
      ></el-table-column>
      <el-table-column
        prop="searchValue"
        label="银行名称"
        width="150"
      ></el-table-column>
      <el-table-column prop="remark" label="备注" min-width="80"></el-table-column>
      <el-table-column prop="createTime" label="申请时间" min-width="100"></el-table-column>
      <el-table-column prop="updateTime" label="打款时间" min-width="100"></el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button
            type="danger"
            @click="refused(scope.row.id)"
            v-if="scope.row.type == '商家申请提现'"
            >驳回</el-button
          >
          <el-button
            type="primary"
            @click="enterSubmit(scope.row.id, 1)"
            v-if="scope.row.type == '商家申请提现'"
            >同意
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <div class="float">
      <el-pagination
        @current-change="pageNumChange"
        :current-page="pageNum"
        :page-size="10"
        background
        layout="total, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </div>

    <el-dialog title="驳回备注" :visible.sync="dialogShow">
      <el-form :model="form">
        <el-form-item label="驳回备注">
          <el-input v-model="form.remarks" autocomplete="off"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogShow = false">取 消</el-button>
        <el-button type="primary" @click="enterSubmit(form.id, 2)">
          确 定
        </el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import {
  recordList,
  reviewWithDrawal,
  exportRecord,
  storeExport,
  storeList,
} from "@/api/ds/store";
import DatePicker from "../../../components/DatePicker/index.vue";

export default {
  components: { DatePicker },
  props: {},
  data() {
    return {
      type: "商家申请提现",
      typeList: ["商家提现失败", "商家申请提现", "商家提现成功"],

      list: [],
      dialogShow: false,
      form: {
        remarks: "",
        id: "",
      },

      total: 0,
      pageNum: 1,

      stid: null,
      cTime: [],
      cTime1: null,
    };
  },
  computed: {},
  watch: {},
  created() {
    this.getData();
  },
  methods: {
    pageNumChange(val) {
      this.pageNum = val;
      this.getData();
    },
    async getData() {
      let query = {
        type: this.type,
        stid: this.stid,
        pageNum: this.pageNum,
        pageSize: 10,
      };


      // 解析参数
      console.log(this.cTime1);
      query = this.addDateRange(query, this.cTime, "");
      if (this.cTime1) {
        query.params["updateBegin"] = this.cTime1[0];
        query.params["updateEnd"] = this.cTime1[1];
      }
      console.log(query);

      let res = await storeList(query);
      if (res.code === 200) {
        this.total = res.total;
        this.list = res.rows;
      }
    },
    refused(id) {
      this.dialogShow = true;
      this.form.id = id;
      this.form.remarks = "";
    },
    /** 导出按钮操作 */
    handleExport() {
      // let queryParams = this.addDateRange(this.detailed, this.id,this.queryTime, "");
      let type = this.type;
      this.$confirm("是否确认导出所有订单数据项?", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(function () {
          return storeExport({ type });
        })
        .then((response) => {
          this.download(response.msg);
        });
    },
    // 同意/驳回
    async enterSubmit(id, type) {
      if (type === 2) {
        let res = await reviewWithDrawal({
          recordId: id,
          type,
          remarks: this.form.remarks,
        });

        if (res.code === 200) {
          this.$notify({
            title: "驳回成功",
            message: res.msg,
            type: "success",
          });
          this.getData();

          this.dialogShow = false;
        }
      } else {
        // 提交成功
        this.$confirm("此操作将打款, 是否继续?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        })
          .then(async () => {
            let res = await reviewWithDrawal({ recordId: id, type });
            if (res.code === 200) {
              this.$notify({
                title: "同意成功",
                message: res.msg,
                type: "success",
              });
              this.getData();

              this.dialogShow = false;
            }
          })
          .catch(() => {
            this.$message({
              type: "info",
              message: "已取消打款",
            });
          });
      }
    },
  },
  mounted() {},
  beforeCreate() {},
  beforeMount() {},
  beforeUpdate() {},
  updated() {},
  beforeDestroy() {},
  destroyed() {},
  activated() {},
  deactivated() {},
};
</script>
<style lang="scss" scoped>
.pages {
  width: 100%;
  min-height: 80vh;
  padding: 20px;

  .float {
    width: 100%;
    height: 50px;

    display: flex;
    justify-content: flex-end;
    align-items: center;
  }
}
</style>
